CPUS=$(shell nproc)
# 源命令文件
SOURCE_FILE=main.go
# 输出
OUTPUT_FILE=bin/gpio-ctl

# 动作: 编译、构建、安装、全平台及架构编译
all:
	@echo '可编译为: windows、linux、drawin(MacOS)'

build: all
	go build -o $(OUTPUT_FILE) $(SOURCE_FILE)

run: build
	exec $(shell find bin/ -maxdepth 1 -type f -executable)

install:
	go install

# Windows 全架构编译
windows-all: windows-amd64 windows-arm64
	@echo "Windows 全架构编译完成"

windows-amd64:
	GOOS=windows GOARCH=amd64 go build -o $(OUTPUT_FILE)-windows-amd64.exe $(SOURCE_FILE)

windows-arm64:
	GOOS=windows GOARCH=arm64 go build -o $(OUTPUT_FILE)-windows-arm64.exe $(SOURCE_FILE)

# Linux 全架构编译
linux-all: linux-amd64 linux-arm linux-arm64
	@echo "Linux 全架构编译完成"

linux-amd64:
	GOOS=linux GOARCH=amd64 go build -o $(OUTPUT_FILE)-linux-amd64 $(SOURCE_FILE)

linux-arm64:
	GOOS=linux GOARCH=arm64 go build -o $(OUTPUT_FILE)-linux-arm64 $(SOURCE_FILE)

linux-arm:
	GOOS=linux GOARCH=arm 	go build -o $(OUTPUT_FILE)-linux-arm $(SOURCE_FILE)


# MacOS (Darwin 全架构编译)
darwin-all: darwin-amd64 darwin-arm64
	@echo "Darwin 全架构编译完成"

darwin-amd64:
	GOOS=darwin GOARCH=amd64 go build -o $(OUTPUT_FILE)-darwin-amd64 $(SOURCE_FILE)

darwin-arm64:
	GOOS=darwin GOARCH=arm64 go build -o $(OUTPUT_FILE)-darwin-arm64 $(SOURCE_FILE)


# FreeBSD 全架构编译
freebsd-all: freebsd-amd64 freebsd-arm64
	@echo "FreeBSD 全架构编译完成"

freebsd-amd64: 
	GOOS=freebsd GOARCH=amd64 go build -o $(OUTPUT_FILE)-freebsd-amd64 $(SOURCE_FILE)

freebsd-arm64: 
	GOOS=freebsd GOARCH=arm64 go build -o $(OUTPUT_FILE)-freebsd-arm64 $(SOURCE_FILE)
